<?php
defined('INCLUDED') or define('INCLUDED',TRUE);
//禁用网页缓存
if (!project::config('config')->webCache){
	header("Cache-control:no-cache,no-store,must-revalidate");  
	header("Pragma:no-cache");  
	header("Expires:0");
}

//upload params
define('HTML_NAME_KEY',1);//上传文件处理后的数组键值为input控件名,name=pic名为pic、name=pic[123]名为123
define('FILE_NAME_KEY',2);//上传文件处理后的数组键值为文件原名

if (!function_exists('get')){//按键取数组值
	function get($a,$k,$default = NULL){
		if (is_array($a) && isset($a[$k])) return $a[$k];
		if (is_object($a) && isset($a->$k)) return $a->$k;
		return $default;
	}
}

if (!function_exists('got')){//按键取数组值
	function got($a,$k,$default = NULL){
		if (is_array($a) && isset($a[$k])) return $a[$k];
		if (is_object($a) && isset($a->$k)) return $a->$k;
		return $default;
	}
}

if (!function_exists('__404')){//404异常处理用户函数
    function __404($e = null,$log = false){
        if (!is_object($e))
        	$e = new lib_exception();
        if ($e instanceof Exception)
        	$e = new lib_exception($e->getMessage(),$e->getCode(),$e->getFile(),$e->getLine());
        if (true === $log){
            $e->log(date("Y-m-d H:i:s ").$e->getMessage().' in '.$e->getFile().' line '.$e->getLine());
        }elseif (is_string($log)){
            $e->log($log);
        }
        ob_get_level() and ob_clean();
        $e->__404();
        exit;
    }
}

if (!function_exists('hook')){//加载视图钩子
	function hook($hook_name,array $vars = array()){
		$hook_path = 'hooks';
		defined('HOOKPATH') or define('HOOKPATH', realpath(APPPATH.$hook_path).DIRECTORY_SEPARATOR);
		if (is_string($hook_name) && !empty($hook_name)){
			if (is_file($file = HOOKPATH.$hook_name.EXT)){
				$hook = include $file;
				if ($hook === 1) return '';
				return (string)$hook;
			}
		}
		return '找不到钩子['.$hook_name.']';
	}
}

if (!project::config('config')->debug){
    set_exception_handler('__404');
}